//
//  ViewController.m
//  DayDay
//
//  Created by wade on 16/5/16.
//  Copyright © 2016年 wade. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize interstitialView = _interstitialView;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.interstitialView = [[BaiduMobAdInterstitial alloc] init];
    self.interstitialView.delegate = self;
    //把在mssp.baidu.com上创建后获得的代码位id写到这里
    self.interstitialView.AdUnitTag = @"2058554";
    //    self.interstitialView.AdUnitTag  =@"2403634"; //WiFi环境下可出视频. 若无填充则出大图.
    self.interstitialView.interstitialType = BaiduMobAdViewTypeInterstitialOther;
    // 加载全屏插屏. 每次仅加载一个广告的物料,若需多次使用请在下次展示前重新执行load方法
    [self.interstitialView load];
    
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.interstitialView.delegate = nil;
    self.interstitialView = nil;
}

- (NSString *)publisherId
{
    return  @"ccb60059"; //@"your_own_app_id"; iOS和Android的app需要使用不同appid
}

-(BOOL) enableLocation
{
    //启用location会有一次alert提示,请根据系统进行相关配置
    return YES;
}

/**
 *  广告预加载成功
 */
- (void)interstitialSuccessToLoadAd:(BaiduMobAdInterstitial *)interstitial
{
    NSLog(@"interstitialSuccessToLoadAd");
    UIAlertView*alv = [[UIAlertView alloc]initWithTitle:@"加载成功" message:@"可以点击显示插屏了" delegate:self cancelButtonTitle:@"好的" otherButtonTitles: nil];
    [alv show];
    
    if (self.interstitialView.isReady){
        [self.interstitialView presentFromRootViewController:self];
    }
    else{
        NSLog(@"not ready!");
    }

}

/**
 *  广告预加载失败
 */
- (void)interstitialFailToLoadAd:(BaiduMobAdInterstitial *)interstitial
{
    NSLog(@"interstitialFailToLoadAd");
    UIAlertView*alv = [[UIAlertView alloc]initWithTitle:@"加载失败" message:@"请重新点击加载插屏" delegate:self cancelButtonTitle:@"好的" otherButtonTitles: nil];
    [alv show];
}

/**
 *  广告即将展示
 */
- (void)interstitialWillPresentScreen:(BaiduMobAdInterstitial *)interstitial
{
    NSLog(@"interstitialWillPresentScreen");
}

/**
 *  广告展示成功
 */
- (void)interstitialSuccessPresentScreen:(BaiduMobAdInterstitial *)interstitial
{
    NSLog(@"interstitialSuccessPresentScreen");
}

/**
 *  广告展示失败
 */
- (void)interstitialFailPresentScreen:(BaiduMobAdInterstitial *)interstitial withError:(BaiduMobFailReason) reason
{
    NSLog(@"interstitialFailPresentScreen, withError: %d",reason);
}

/**
 *  广告展示结束
 */
- (void)interstitialDidDismissScreen:(BaiduMobAdInterstitial *)interstitial
{
    NSLog(@"interstitialDidDismissScreen");
}


@end
